package com.yjhealth.libs.businessdemo.business;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import com.yjhealth.libs.businessdemo.R;
import com.yjhealth.libs.businessdemo.databinding.BusinessdemoActivityDemoBaseBinding;
import com.yjhealth.libs.commonlib.base.activity.BaseActivity;
import com.yjhealth.libs.commonlib.event.LoginEvent;
import com.yjhealth.libs.core.utils.EffectUtil;
import com.yjhealth.libs.core.view.dialog.CoreConfirmDialog;
import com.yjhealth.libs.core.view.titlebar.BsoftToolbar;
import com.yjhealth.libs.core.view.titlebar.config.TitleButtonConfig;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

public class DemoBaseActivity extends BaseActivity {
    /*Default*/
    /*Util*/
    private Handler handler = new Handler();
    /*Flag*/
    /*View*/
    private BusinessdemoActivityDemoBaseBinding binding;
    private CoreConfirmDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(activity, R.layout.businessdemo_activity_demo_base);

        initLayout();

        EffectUtil.addClickEffect( binding.tvTest);
        binding.tvTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                showLoadingView();
                handler.postDelayed(runnable, 0);
            }
        });

        dialog = CoreConfirmDialog
                .newInstance(getString(R.string.yjhealth_core_remind),
                        "2222222222222",
                        getString(R.string.yjhealth_core_ok),
                        null);
        dialog.setCommonDialogListener(new CoreConfirmDialog.CommonDialogListener() {
            @Override
            public void onComplete(boolean ok, String tag) {

            }
        });

        dialog.dismiss();
    }

    @Override
    protected void initLayout() {
        super.initLayout();
//        binding.bsoftToolbar.setTitle("111");
        binding.yjhealthCoreBosftToolbar.setLisntener(new BsoftToolbar.OnBsoftToolbarLisntener() {
            @Override
            public void onItemClick(TitleButtonConfig config) {
            }

            @Override
            public void onBack() {
                onBackPressed();
            }

            @Override
            public void updateStatusBar() {
                setStatusBar();
            }
        });

        ArrayList<TitleButtonConfig> configs = new ArrayList<>();
        TitleButtonConfig config = new TitleButtonConfig();
        config.name = "提交";
        config.iconLocal = R.mipmap.ic_launcher;
        config.showMode = TitleButtonConfig.SHOW_MODE_ALL;
        configs.add(config);
        binding.yjhealthCoreBosftToolbar.setTitleButton(configs);

    }

    @Override
    protected void setStatusBar() {
        binding.yjhealthCoreBosftToolbar.setStatusBar();
    }

    @Override
    public boolean dataBindingMode() {
        return true;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacks(runnable);
    }

    @Override
    protected void onRefreshView() {
        showLoadingView();
        handler.postDelayed(runnable, 3000);
    }

    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            dialog.show(getFragmentManager());
        }
    };

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void event(LoginEvent coreEvent) {

    }
}
